//
//  AnswerInvitedRecomendLocalVC.m
//  OnionHome
//
//  Created by fengjie on 2019/9/23.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "AnswerInvitedRecomendLocalVC.h"
#import "SerachQuestionAndAnswerVC.h"

@interface AnswerInvitedRecomendLocalVC ()<UITableViewDelegate,UITableViewDataSource>
/**邀请按钮*/
@property (nonatomic,strong)UIButton*invitdBtn;
/**推荐*/
@property (nonatomic,strong)UIButton*recomendBtn;
/**本地按钮*/
@property (nonatomic,strong)UIButton*localBtn;

/**轮播图*/
@property (nonatomic,strong)SDCycleScrollView*cycleView;
/**listView*/
@property (nonatomic,strong)UITableView*listView;
@end

@implementation AnswerInvitedRecomendLocalVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.titleView = [self setNavTitleView];
    [self addNavigationItemWithImageNames:@[@"ic_nav_search"] isLeft:NO target:self action:@selector(rightAction) tags:nil];
    [self createUI];
}

/// 点击搜索图标
-(void)rightAction{
    [self.navigationController presentViewController:[[BasseNavigationController alloc]initWithRootViewController:[SerachQuestionAndAnswerVC new]] animated:YES completion:nil];
}
-(void)createUI{
    [self.view addSubview:self.cycleView];
    [self.view addSubview:self.listView];
    
    [self.cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(188);
    }];
    
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(self.cycleView.mas_bottom);
    }];
    
}
#pragma mark -UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AnswerInvitedRecomendLocalOneCell * oneCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AnswerInvitedRecomendLocalOneCell class])];
    AnswerInvitedRecomendLocalTwoCell * twoCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AnswerInvitedRecomendLocalTwoCell class])];
    if (self.invitdBtn.selected == YES) {
        return oneCell;
    }

    return twoCell;
}
#pragma mark ---懒加载
-(UITableView*)listView{
    if(!_listView){
        _listView=[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[AnswerInvitedRecomendLocalOneCell class] forCellReuseIdentifier:NSStringFromClass([AnswerInvitedRecomendLocalOneCell class])];
        [_listView registerClass:[AnswerInvitedRecomendLocalTwoCell class] forCellReuseIdentifier:NSStringFromClass([AnswerInvitedRecomendLocalTwoCell class])];
        [_listView setSeparatorColor:UIColorFromRGB(0xE9EEE7)];
        [_listView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    return _listView;
}
-(UIView *)setNavTitleView{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
    view.userInteractionEnabled = YES;

    [view addSubview:self.invitdBtn];
    [view addSubview:self.recomendBtn];
    [view addSubview:self.localBtn];

    
    [self.invitdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0);
    }];
    [self.recomendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.invitdBtn.mas_right).offset(60);
        make.center.mas_equalTo(0);
    }];
    [self.localBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.recomendBtn.mas_right).offset(60);
        make.right.top.bottom.mas_equalTo(0);
    }];

    return view;
}

-(UIButton*)invitdBtn{
    if(!_invitdBtn){
        _invitdBtn=[UIButton new];
        [_invitdBtn setTitle:@"邀请" forState:UIControlStateNormal];
        [_invitdBtn setTitleColor:UIColorFromRGB(0x009966) forState:UIControlStateSelected];
        [_invitdBtn setTitleColor:UIColorFromRGB(0x273323) forState:UIControlStateNormal];
        _invitdBtn.titleLabel.font = SYSTEMFONT(16);
        _invitdBtn.selected = YES;
        
        kWeakSelf(weakSelf);
        [_invitdBtn addActionHandler:^{
            weakSelf.invitdBtn.selected = YES;
            weakSelf.recomendBtn.selected = NO;
            weakSelf.localBtn.selected = NO;
            [weakSelf.listView reloadData];
        }];
    }
    return _invitdBtn;
}
-(UIButton*)recomendBtn{
    if(!_recomendBtn){
        _recomendBtn=[UIButton new];
        [_recomendBtn setTitle:@"推荐" forState:UIControlStateNormal];
        [_recomendBtn setTitleColor:UIColorFromRGB(0x009966) forState:UIControlStateSelected];
        [_recomendBtn setTitleColor:UIColorFromRGB(0x273323) forState:UIControlStateNormal];
        _recomendBtn.titleLabel.font = SYSTEMFONT(16);
        kWeakSelf(weakSelf);
        [_recomendBtn addActionHandler:^{
            weakSelf.invitdBtn.selected = NO;
            weakSelf.recomendBtn.selected = YES;
            weakSelf.localBtn.selected = NO;
            [weakSelf.listView reloadData];
        }];

    }
    return _recomendBtn;
}
-(UIButton*)localBtn{
    if(!_localBtn){
        _localBtn=[UIButton new];
        [_localBtn setTitle:@"本地" forState:UIControlStateNormal];
        [_localBtn setTitleColor:UIColorFromRGB(0x009966) forState:UIControlStateSelected];
        [_localBtn setTitleColor:UIColorFromRGB(0x273323) forState:UIControlStateNormal];
        _localBtn.titleLabel.font = SYSTEMFONT(16);
        kWeakSelf(weakSelf);
        [_localBtn addActionHandler:^{
            weakSelf.invitdBtn.selected = NO;
            weakSelf.recomendBtn.selected = NO;
            weakSelf.localBtn.selected = YES;
            [weakSelf.listView reloadData];
        }];

    }
    return _localBtn;
}
-(SDCycleScrollView*)cycleView{
    if(!_cycleView){
        _cycleView=[SDCycleScrollView new];
        _cycleView.imageURLStringsGroup = @[[Utilis getRandomDynamicImage],[Utilis getRandomDynamicImage],[Utilis getRandomDynamicImage]];
    }
    return _cycleView;
}
@end

#pragma mark --AnswerInvitedRecomendLocalOneCell


@interface AnswerInvitedRecomendLocalOneCell ()

@end

@implementation AnswerInvitedRecomendLocalOneCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)createUI{
    UIImageView * iconImage = UIImageView.new;
    iconImage.image = IMAGE_NAMED(@"userIconDefut");
    iconImage.layer.cornerRadius = 14;
    
    UILabel * nameLabel = UILabel.new;
    nameLabel.textColor = UIColorFromRGB(0x273323);
    nameLabel.font = BOLDSYSTEMFONT(14);
    nameLabel.text = @"我是大鲨鱼";
    
    UILabel * oneLabel = UILabel.new;
    oneLabel.textColor = UIColorFromRGB(0x273323);
    oneLabel.font = SYSTEMFONT(14);
    oneLabel.text = @"邀请回答";

    UILabel * contenxLabel = UILabel.new;
    contenxLabel.textColor = UIColorFromRGB(0x273323);
    contenxLabel.font = BOLDSYSTEMFONT(18);
    contenxLabel.text = @"现代人大多处于亚健康，与饮食的关系？";
    contenxLabel.numberOfLines = 0;

    UILabel * numberLabel = UILabel.new;
    numberLabel.textColor = UIColorFromRGB(0x959E97);
    numberLabel.font = SYSTEMFONT(12);
    numberLabel.text = @"0个回答";
    
    UIButton * deleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleBtn setTitle:@"忽略" forState:UIControlStateNormal];
    [deleBtn setTitleColor:UIColorFromRGB(0x454F44) forState:UIControlStateNormal];
    deleBtn.titleLabel.font = SYSTEMFONT(12);
    
    [self addSubview:iconImage];
    [self addSubview:nameLabel];
    [self addSubview:oneLabel];
    [self addSubview:contenxLabel];
    [self addSubview:numberLabel];
    [self addSubview:deleBtn];
    
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.width.height.mas_equalTo(28);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(iconImage);
        make.left.mas_equalTo(iconImage.mas_right).offset(8);
    }];
    [oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(iconImage);
        make.left.mas_equalTo(nameLabel.mas_right).offset(8);
    }];
    [contenxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(iconImage.mas_bottom).offset(8);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
    }];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(contenxLabel.mas_bottom).offset(8);
        make.left.mas_equalTo(16);
    }];
    [deleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(numberLabel);
        make.bottom.right.mas_equalTo(-16);
    }];

}



@end



#pragma mark --AnswerInvitedRecomendLocalTwoCell

@interface AnswerInvitedRecomendLocalTwoCell ()

@end

@implementation AnswerInvitedRecomendLocalTwoCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)createUI{
    UILabel * contenxLabel = UILabel.new;
    contenxLabel.textColor = UIColorFromRGB(0x273323);
    contenxLabel.font = BOLDSYSTEMFONT(18);
    contenxLabel.text = @"现代人大多处于亚健康，与饮食的关系？";
    contenxLabel.numberOfLines = 0;

    UILabel * numberLabel = UILabel.new;
    numberLabel.textColor = UIColorFromRGB(0x959E97);
    numberLabel.font = SYSTEMFONT(12);
    numberLabel.text = @"0个回答";
    
    UIButton * deleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleBtn setBackgroundImage:IMAGE_NAMED(@"icon_quxiao") forState:UIControlStateNormal];
//    [deleBtn setTitle:@"忽略" forState:UIControlStateNormal];
//    [deleBtn setTitleColor:UIColorFromRGB(0x454F44) forState:UIControlStateNormal];
//    deleBtn.titleLabel.font = SYSTEMFONT(12);
    
    [self addSubview:contenxLabel];
    [self addSubview:numberLabel];
    [self addSubview:deleBtn];
    
    [contenxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.right.mas_equalTo(-16);
    }];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(contenxLabel.mas_bottom).offset(8);
        make.left.mas_equalTo(16);
    }];
    [deleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(numberLabel);
        make.bottom.right.mas_equalTo(-16);
    }];

}


@end
